Make repeated calls accumulate the results, don't call qsort() on empty
authorMatthias Clasen <mclasen@redhat.com>
Thu, 9 Dec 2004 14:15:00 +0000 (14:15 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 9 Dec 2004 14:15:00 +0000 (14:15 +0000)
2004-12-09  Matthias Clasen  <mclasen@redhat.com>

* xdgmimealias.c (_xdg_mime_alias_read_from_file):
* xdgmimeparent.c (_xdg_mime_parent_read_from_file): Make
repeated calls accumulate the results, don't call qsort()
on empty arrays.  (#160838, Mariano Suárez-Alvarez)

gtk/xdgmime/ChangeLog
gtk/xdgmime/xdgmimealias.c
gtk/xdgmime/xdgmimeparent.c

index a14b625b14da31bfd99fbb1c9f19598c2a5d68da..bf7c0e68baa5113c3b0a99925a02bddd225922e5 100644 (file)
@@ -1,3 +1,10 @@
+2004-12-09  Matthias Clasen  <mclasen@redhat.com>
+
+       * xdgmimealias.c (_xdg_mime_alias_read_from_file): 
+       * xdgmimeparent.c (_xdg_mime_parent_read_from_file): Make
+       repeated calls accumulate the results, don't call qsort()
+       on empty arrays.  (#160838, Mariano Suárez-Alvarez)
+
 2004-12-02  Matthias Clasen  <mclasen@redhat.com>
 
        * === Released 2.5.6 ===
index 2be3d3711c8d0cdfa837e884eb8c9d8ee277ba23..1a40e0b71887a8567b5fe0e55952c57f539ef33c 100644 (file)
@@ -128,8 +128,8 @@ _xdg_mime_alias_read_from_file (XdgAliasList *list,
 
   /* FIXME: Not UTF-8 safe.  Doesn't work if lines are greater than 255 chars.
    * Blah */
-  alloc = 16;
-  list->aliases = malloc (alloc * sizeof (XdgAlias));
+  alloc = list->n_aliases + 16;
+  list->aliases = realloc (list->aliases, alloc * sizeof (XdgAlias));
   while (fgets (line, 255, file) != NULL)
     {
       char *sep;
@@ -156,8 +156,9 @@ _xdg_mime_alias_read_from_file (XdgAliasList *list,
 
   fclose (file);  
   
-  qsort (list->aliases, list->n_aliases, 
-        sizeof (XdgAlias), alias_entry_cmp);
+  if (list->n_aliases > 1)
+    qsort (list->aliases, list->n_aliases, 
+           sizeof (XdgAlias), alias_entry_cmp);
 }
 
 
index f623fb2d1c08e9a64032f5d0daa6487ed51c4823..fc97b3ea2b31ab861e9b57b5e9ae02e204031992 100644 (file)
@@ -134,8 +134,8 @@ _xdg_mime_parent_read_from_file (XdgParentList *list,
 
   /* FIXME: Not UTF-8 safe.  Doesn't work if lines are greater than 255 chars.
    * Blah */
-  alloc = 16;
-  list->parents = malloc (alloc * sizeof (XdgMimeParents));
+  alloc = list->n_mimes + 16;
+  list->parents = realloc (list->parents, alloc * sizeof (XdgMimeParents));
   while (fgets (line, 255, file) != NULL)
     {
       char *sep;
@@ -191,8 +191,9 @@ _xdg_mime_parent_read_from_file (XdgParentList *list,
 
   fclose (file);  
   
-  qsort (list->parents, list->n_mimes, 
-        sizeof (XdgMimeParents), &parent_entry_cmp);
+  if (list->n_mimes > 1)
+    qsort (list->parents, list->n_mimes, 
+           sizeof (XdgMimeParents), &parent_entry_cmp);
 }